package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import java.io.Serializable;
import java.math.*;
import javax.persistence.*;


@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("XACT")
/**
 * 代表了两个帐户之间金额活动
 */
public class FinancialTransaction extends Act implements Serializable {

	private static final long serialVersionUID = 1L;

	// 交易金额
	@SuppressWarnings("unused")
	@Transient
	private MO amt;

	// 一个十进制数表示的汇率兑换货币的帐户被记入净额的交易货币。
	@SuppressWarnings("unused")
	@Transient
	private REAL creditExchangeRateQuantity;

	// 一个十进制数表示的汇率兑换货币的帐户被扣除交易的净额货币。
	@SuppressWarnings("unused")
	@Transient
	private REAL debitExchangeRateQuantity;

	public FinancialTransaction() throws Hl7Exception {
	}


	// 交易金额
	public MO getAmt() throws Hl7Exception {
		if (ftFinancialTransAmt != null && ftFinancialTransAmtTxt != null) {
			return DataTypeUtil.getMO(ftFinancialTransAmt,
					ftFinancialTransAmtTxt);
		} else {
			return null;
		}
	}

	public void setAmt(MO amt) throws Hl7Exception {
		if (amt != null) {
			this.ftFinancialTransAmt = amt.value().doubleValue();
			this.ftFinancialTransAmtTxt = amt.currency().code().stringValue();
		}
	}

	// 一个十进制数表示的汇率兑换货币的帐户被记入净额的交易货币。
	public REAL getCreditExchangeRateQuantity() throws Hl7Exception {
		if (ftCrdExchangeRateQtyTxt != null
				&& !"".equals(ftCrdExchangeRateQtyTxt)) {
			return DataTypeUtil.getREAL(ftCrdExchangeRateQtyTxt);
		} else if (ftCrdExchangeRateQtyNum != null) {
			return DataTypeUtil
					.getREAL(new BigDecimal(ftCrdExchangeRateQtyNum));
		} else {
			return null;
		}
	}

	public void setCreditExchangeRateQuantity(REAL creditExchangeRateQuantity) {
		if (creditExchangeRateQuantity != null) {
			ftCrdExchangeRateQtyTxt = creditExchangeRateQuantity.stringValue();
			ftCrdExchangeRateQtyNum = creditExchangeRateQuantity
					.bigDecimalValue().longValue();
		}
	}

	// 一个十进制数表示的汇率兑换货币的帐户被扣除交易的净额货币。
	public REAL getDebitExchangeRateQuantity() throws Hl7Exception {
		if (ftDbtExchangeRateQtyTxt != null
				&& !"".equals(ftDbtExchangeRateQtyTxt)) {
			return DataTypeUtil.getREAL(ftDbtExchangeRateQtyTxt);
		} else if (ftDbtExchangeRateQtyNum != null) {
			return DataTypeUtil
					.getREAL(new BigDecimal(ftDbtExchangeRateQtyNum));
		} else {
			return null;
		}
	}

	public void setDebitExchangeRateQuantity(REAL debitExchangeRateQuantity) {

		if (debitExchangeRateQuantity != null) {
			ftDbtExchangeRateQtyTxt = debitExchangeRateQuantity.stringValue();
			ftDbtExchangeRateQtyNum = debitExchangeRateQuantity
					.bigDecimalValue().longValue();
		}
	}

	// FinancialTransaction
	@Column(name = "FT_CRD_EXCHANGE_RATE_QTY_NUM")
	private Long ftCrdExchangeRateQtyNum;
	@Column(name = "FT_CRD_EXCHANGE_RATE_QTY_TXT")
	private String ftCrdExchangeRateQtyTxt;
	@Column(name = "FT_DBT_EXCHANGE_RATE_QTY_NUM")
	private Long ftDbtExchangeRateQtyNum;
	@Column(name = "FT_DBT_EXCHANGE_RATE_QTY_TXT")
	private String ftDbtExchangeRateQtyTxt;
	@Column(name = "FT_FINANCIAL_TRANS_AMT")
	private Double ftFinancialTransAmt;
	@Column(name = "FT_FINANCIAL_TRANS_AMT_TXT")
	private String ftFinancialTransAmtTxt;
	@Column(name = "FT_FIN_TRAN_CURR_CODE")
	private String ftFinTranCurrCode;

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

}
